package com.zhou.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import com.zhou.util.JsonUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Data//自动get/set
@NoArgsConstructor//自动有参构造
@AllArgsConstructor//自动无参构造
@ToString//自动ToString方法
@EqualsAndHashCode//自动Equals和HashCode方法
@ApiModel("用户对象")
@TableName("user")
public class User {
    @ApiModelProperty("用户ID")
    private int id;
    @ApiModelProperty("用户年龄")
    private Integer age;
    @ApiModelProperty("用户名字")
    private String name;
    @ApiModelProperty("用户密码")
    private String password;


    @TableField(exist = false)
    private List<Book> borrowedBooks = new ArrayList<>(); // 当前借阅的书籍
    @TableField(exist = false)
    private String bookListJson;

    public User(int id, Integer age, String name, String bookListJson) {
        this.id = id;
        this.age = age;
        this.name = name;
        this.bookListJson = bookListJson;

        List deserialize = null;
        try {
            deserialize = JsonUtil.deserialize(bookListJson, List.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.borrowedBooks=deserialize;
    }
}
